﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:tb="clr-namespace:Toolbox;assembly=Toolbox" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colors.xaml" />
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseDark.xaml" />
    </ResourceDictionary.MergedDictionaries>
    
    <!-- Colours -->
    <SolidColorBrush x:Key="UIBackgroundBrush">
        <SolidColorBrush.Color>
            <Color A="255" R="45" G="45" B="45" />
        </SolidColorBrush.Color>
    </SolidColorBrush>
    <SolidColorBrush x:Key="UIAltBackgroundBrush" Color="{StaticResource AccentColor}" />
    <SolidColorBrush x:Key="UIMiddleForegroundBrush">
        <SolidColorBrush.Color>
            <Color A="255" R="205" G="205" B="205" />
        </SolidColorBrush.Color>
    </SolidColorBrush>
    <SolidColorBrush x:Key="UISelectedBackgroundBrush">
        <SolidColorBrush.Color>
            <Color A="255" R="75" G="75" B="75" />
        </SolidColorBrush.Color>
    </SolidColorBrush>
    <SolidColorBrush x:Key="UIForegroundBrush" Color="White" />
    <SolidColorBrush x:Key="UIMouseOverBrush">
        <SolidColorBrush.Color>
            <Color A="255" R="255" G="240" B="150" />
        </SolidColorBrush.Color>
    </SolidColorBrush>
    <SolidColorBrush x:Key="UISelectedBrush" Color="{StaticResource AccentColor}" />
    
    <Style x:Key="StatusBarStyle" TargetType="{x:Type StatusBar}">
        <Setter Property="Background" Value="{StaticResource UIAltBackgroundBrush}" />
        <Setter Property="Foreground" Value="{StaticResource UIForegroundBrush}" />
    </Style>

    <Style x:Key="ToolboxStyle" TargetType="{x:Type tb:Toolbox}">
        <Setter Property="Background" Value="{StaticResource UIBackgroundBrush}" />
    </Style>

    <BorderGapMaskConverter x:Key="BorderGapMaskConverter"/>

    <Style x:Key="ToolboxItemStyle" TargetType="{x:Type tb:ToolboxItem}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type tb:ToolboxItem}">
                    <Grid Width="45" Height="45">
                        <Border Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}">
                            <ContentPresenter ContentTemplate="{TemplateBinding ToolboxItemContentTemplate}" />
                        </Border>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Width" Value="45" />
        <Setter Property="Height" Value="45" />
        <Setter Property="Background" Value="{StaticResource UIBackgroundBrush}" />
        <Setter Property="Foreground" Value="{StaticResource UIMiddleForegroundBrush}" />
        <Setter Property="Margin" Value="3,0,0,0" />
        <Style.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter Property="Background" Value="{StaticResource UISelectedBackgroundBrush}" />
            </Trigger>
        </Style.Triggers>
    </Style>
    
    <Style x:Key="ToolboxCategoryStyle" TargetType="{x:Type tb:ToolboxCategory}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type tb:ToolboxCategory}">
                    <Grid>
                        <Rectangle Name="SelectedRect" Width="5" Height="45" HorizontalAlignment="Left" />
                        <Border Name="MainBorder" Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">
                            <ContentPresenter Content="{TemplateBinding MainItem}" Width="45" ContentTemplate="{TemplateBinding MainItemTemplate}" />
                        </Border>
                        <Canvas Name="ExpanderCanvas" Visibility="Collapsed">
                            <Path Width="5.57359" Height="8.70267" Canvas.Right="6" Canvas.Bottom="4" Stretch="Fill" Fill="#FF5E5E5E" Data="F1 M 44.1443,39.0107L 38.5707,34.6594L 38.5707,43.362L 44.1443,39.0107 Z "/>
                        </Canvas>
                        <Popup Name="Popup" PlacementRectangle="2,0,55,50" Placement="Right" IsOpen="{TemplateBinding IsExpanded}" AllowsTransparency="True" Focusable="False" PopupAnimation="Fade">
                            <Border Name="SubmenuBorder" SnapsToDevicePixels="True" BorderThickness="0" Background="{StaticResource UIBackgroundBrush}">
                                <StackPanel Orientation="Horizontal" IsItemsHost="True" />
                            </Border>
                        </Popup>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsExpanderVisible" Value="True">
                            <Setter TargetName="ExpanderCanvas" Property="Visibility" Value="Visible" />
                        </Trigger>
                        <Trigger Property="IsSelectedCategory" Value="True">
                            <Setter TargetName="SelectedRect" Property="Fill" Value="{StaticResource UISelectedBrush}" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="SelectedRect" Property="Fill" Value="{StaticResource UIMouseOverBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="Width" Value="Auto" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="Margin" Value="0,5,0,0" />
        <Setter Property="ItemContainerStyle" Value="{StaticResource ToolboxItemStyle}" />
    </Style>

    <Style x:Key="ToolboxScrollViewer" TargetType="{x:Type ScrollViewer}">
        <Setter Property="OverridesDefaultStyle" Value="True"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ScrollViewer}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto"/>
                            <ColumnDefinition/>
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition/>
                            <RowDefinition Height="Auto"/>
                        </Grid.RowDefinitions>

                        <ScrollContentPresenter Grid.Column="1"/>

                        <ScrollBar Name="PART_VerticalScrollBar"
            Value="{TemplateBinding VerticalOffset}"
            Maximum="{TemplateBinding ScrollableHeight}"
            ViewportSize="{TemplateBinding ViewportHeight}"
            Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}"/>
                        <ScrollBar Name="PART_HorizontalScrollBar"
            Orientation="Horizontal"
            Grid.Row="1"
            Grid.Column="1"
            Value="{TemplateBinding HorizontalOffset}"
            Maximum="{TemplateBinding ScrollableWidth}"
            ViewportSize="{TemplateBinding ViewportWidth}"
            Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}"/>

                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="SelectLabel" TargetType="{x:Type TextBox}">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="BorderBrush" Value="{x:Null}"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="IsTabStop" Value="False"/>
        <Setter Property="Padding" Value="4" />
    </Style>

    <SolidColorBrush x:Key="CDContextMenuBackground" Color="#1B1B1C" />
    <Style x:Key="ContextMenuStyle" TargetType="ContextMenu">        
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate>
                    <Grid Margin="0,0,5,5">
                        <!--Border 2-->
                        <Border x:Name="SubMenuBorder"
                                            BorderBrush="{StaticResource CDContextMenuBackground}"
                                            BorderThickness="1"
                                            Background="{StaticResource CDContextMenuBackground}"
                                            SnapsToDevicePixels="True">
                            <Grid x:Name="SubMenu"
                                              Grid.IsSharedSizeScope="True"
                                              Margin="2">
                                <StackPanel IsItemsHost="True"
                                                        KeyboardNavigation.DirectionalNavigation="Cycle" />
                            </Grid>
                            <Border.Effect>
                                <DropShadowEffect ShadowDepth="2"
                                                              Color="Black" />
                            </Border.Effect>
                        </Border>
                        <!--Border 3-->
                        <Border Margin="1,0,0,0"
                                            x:Name="TransitionBorder"
                                            Width="0"
                                            Height="2"
                                            VerticalAlignment="Top"
                                            HorizontalAlignment="Left"
                                            Background="{StaticResource CDContextMenuBackground}"
                                            SnapsToDevicePixels="False"
                                            BorderThickness="1"
                                            BorderBrush="{StaticResource CDContextMenuBackground}" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ContextMenuItemStyle" TargetType="MenuItem">
        <Setter Property="Padding" Value="3" />
    </Style>

    <Style x:Key="CDTabControl" TargetType="{x:Type TabControl}">
        <Style.Resources>
            <Style TargetType="{x:Type TabItem}">
                <Setter Property="FocusVisualStyle"
                        Value="{x:Null}" />
                <Setter Property="Background"
                        Value="Transparent" />
                <Setter Property="Foreground" Value="White" />
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="{x:Type TabItem}">
                            <Grid Height="30"
                                  Background="{TemplateBinding Background}"
                                  SnapsToDevicePixels="true">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto" />
                                </Grid.ColumnDefinitions>
                                <ContentPresenter Grid.Column="0"
                                                  Margin="10,0,10,0"
                                                  HorizontalAlignment="Center"
                                                  VerticalAlignment="Center"
                                                  ContentSource="Header" />
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsSelected"
                                         Value="false">
                                    <Setter Property="Background"
                                            Value="Transparent" />
                                </Trigger>
                                <Trigger Property="IsMouseOver"
                                         Value="true">
                                    <Setter Property="Background"
                                            Value="{DynamicResource BorderBrushSelected}" />
                                </Trigger>
                                <Trigger Property="IsSelected"
                                         Value="true">
                                    <Setter Property="Background"
                                            Value="{DynamicResource BackgroundSelected}" />
                                </Trigger>
                            </ControlTemplate.Triggers>
                        </ControlTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Style.Resources>

        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabControl}">
                    <Grid KeyboardNavigation.TabNavigation="Local">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                        </Grid.RowDefinitions>
                        <Border Background="Transparent"
                                BorderBrush="{DynamicResource BackgroundSelected}"
                                BorderThickness="0,0,0,3">
                            <TabPanel Name="HeaderPanel"
                                      Margin="0,0,4,-1"
                                      Panel.ZIndex="1"
                                      IsItemsHost="True"
                                      KeyboardNavigation.TabIndex="1" />
                        </Border>
                        <Border Grid.Row="1"
                                Background="{DynamicResource Background}" />
                        <ContentPresenter Name="PART_SelectedContentHost"
                                          Grid.Row="1"
                                          ContentSource="SelectedContent" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>